<%@ page language="java" contentType="text/html; charset=UTF-8"  pageEncoding="UTF-8"%>
var add_person = "";

$(function(){
	
	hide_type_level();
	
	$("#saveButton").click(function(){
		if($("#scheduleForm").form('validate')){
			$(this).attr("disabled",true);
			save();
		}
	});
	
	$("#schedule_startime").datetimebox({
		onHidePanel : function() {
			onChangeStartTime();
	    }
	});

	$("#schedule_endtime").datetimebox({
		onHidePanel : function() {
			onChangeEndTime();
	    }
	});
	
});


function save(){
	var schedule_person = $("#schedule_person").val();
	var schedule_type = $("#schedule_type").val();
	var schedule_level = $("#calendar_level").val();
	var schedule_startime = $("#schedule_startime").val();
	var schedule_endtime = $("#schedule_endtime").val();
	var schedule_theme = $("#schedule_theme").val();
	var schedule_content = $("#schedule_content").val();
	var uid = "${uuid}";
	var createPerson_uid = "${createPerson_uuid}";
	var updatePerson_uid = "${updatePerson_uuid}";
	var lingdao = "${lingDao}";
	if(lingdao == "0"){
		if((uid!="") && (createPerson_uid!="") && (updatePerson_uid!="") && (schedule_person!="") && (schedule_startime!="") && (schedule_endtime!="") && (schedule_theme!="") && (schedule_content!="")){
			$.ajax({
				type: "POST",
				url: "/document/schedule/save",
				data: {uuid:uid, s_createPerson_uuid:createPerson_uid, s_updatePerson_uuid:updatePerson_uid, person:schedule_person, type:schedule_type, level:schedule_level, startime:schedule_startime, endtime:schedule_endtime, theme:schedule_theme, content:schedule_content},
				dataType: 'json',
				success: function(data){
					if(data.status == "200"){
						//$.messager.alert("提示","新增日程保存成功");
						parent.closeDialog();
					}else{
						$.messager.alert("提示","新增日程保存失败");
					}
					
				}
			});
		}else{
			$.messager.alert("提示","请填写日程信息！");
		}
	}else{
		if((uid!="") && (createPerson_uid!="") && (updatePerson_uid!="") && (schedule_person!="") && (schedule_type!="") && (schedule_level!="") && (schedule_startime!="") && (schedule_endtime!="") && (schedule_theme!="") && (schedule_content!="")){
			$.ajax({
				type: "POST",
				url: "/document/schedule/save",
				data: {uuid:uid, s_createPerson_uuid:createPerson_uid, s_updatePerson_uuid:updatePerson_uid, person:schedule_person, type:schedule_type, level:schedule_level, startime:schedule_startime, endtime:schedule_endtime, theme:schedule_theme, content:schedule_content},
				dataType: 'json',
				success: function(data){
					if(data.status == "200"){
						//$.messager.alert("提示","新增日程保存成功");
						parent.closeDialog();
					}else{
						$.messager.alert("提示","新增日程保存失败");
					}
					
				}
			});
		}else{
			$.messager.alert("提示","请填写日程信息！");
		}
	}
}

function onChangeStartTime(){
	var startTime = $("#schedule_startime").val();//开始时间
	var endTime = $("#schedule_endtime").val();//结束时间
	if(startTime!=null&&startTime!=""&&endTime!=null&&endTime!=""){
		if(startTime>endTime){
			 $.messager.alert('提示','开始时间不能大于结束时间!');
			 $('#schedule_startime').datetimebox('setValue', ''); 
			 return;
		}
	}	
}

function onChangeEndTime(){
	var startTime = $("#schedule_startime").val();//开始时间
	var endTime = $("#schedule_endtime").val();//结束时间
	if(startTime!=null&&startTime!=""&&endTime!=null&&endTime!=""){
		if(startTime>endTime){
			 $.messager.alert('提示','开始时间不能大于结束时间!');
			 $('#schedule_endtime').datetimebox('setValue', ''); 
			 return;
		}
	}	
}

function hide_type_level(){
	var lingdao = "${lingDao}";
	if(lingdao == "0"){
		$("#hide_type_level").hide();
	}else{
		$("#hide_type_level").show();
	}
}


